package com.dubbo.consumer.Annotation;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dubbo.dubbo.Annotation.IHelloAnnotationService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * 注解方式的service
 */
@Component("annotatedConsumer")
public class ConsumerAnnotationService {
//    @Reference //用于依赖注入，一般注入的是分布式的远程服务的对象
    @DubboReference
    private IHelloAnnotationService providerServiceAnnotation;

    public String doSayHello(String name) {
        return providerServiceAnnotation.HelloBoy(name);
    }

    @HystrixCommand(fallbackMethod = "failBackMethod")
    public String doSayHelloHystrix(String name) {
        return providerServiceAnnotation.HelloHystrix(name);
    }

    /**
     * 服务降级
     * @param name
     * @return
     */
    public String failBackMethod(String name) {
        return "service request fail - "+name;
    }
}
